/*
 * Copyright (c) 2008-2009 Bill Whitacre http://rampancy.g0dsoft.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
*/

#ifndef RAT_PHYSICS_VECTOR
#define RAT_PHYSICS_VECTOR

#include "common.h"
#include "transform.h"

typedef struct vector2
{
	rat_real x;
	rat_real y;
} vector2;

#ifdef __cplusplus
extern "C" {
#endif

void vector2_init(vector2 *vector);
void vector2_set(vector2 *vector,rat_real x,rat_real y);
void vector2_angleunit(vector2 *vector,rat_real angle);

rat_real vector2_dot(vector2 a,vector2 b);
rat_real vector2_cross(vector2 a,vector2 b);

vector2 vector2_add(vector2 a,vector2 b);
vector2 vector2_sub(vector2 a,vector2 b);
vector2 vector2_multf(vector2 a,rat_real val);
vector2 vector2_multvec(vector2 a,vector2 b);

void vector2_plus(vector2 *self,vector2 oth);
void vector2_minus(vector2 *self,vector2 oth);
void vector2_timesf(vector2 *self,rat_real val);
void vector2_timesvec(vector2 *self,vector2 oth);

rat_real vector2_magnitudesquared(vector2 vector);

vector2 vector2_average(vector2 *pts,unsigned int numpts);
rat_real vector2_magnitude(vector2 vector);

rat_real vector2_distancesquared(vector2 a,vector2 b);
void vector2_normalize(vector2 *vector);
vector2 vector2_getnormalized(vector2 vector);

vector2 vector2_project(vector2 a,vector2 b);

rat_real vector2_distance(vector2 a,vector2 b);
vector2 vector2_reflect(vector2 instance,vector2 normal);
rat_real vector2_angle(vector2 vector);
vector2 vector2_perp_left(vector2 vector);
vector2 vector2_perp_right(vector2 vector);
vector2 vector2_negative(vector2 vector);

vector2 vector2_getrotated(vector2 vector,rat_real angle);
vector2 vector2_getscaled(vector2 vector,vector2 scalar);
vector2 vector2_gettranslated(vector2 vector,vector2 trans);

void vector2_rotate(vector2 *self,rat_real angle);
void vector2_scale(vector2 *self,vector2 scalar);
void vector2_translate(vector2 *self,vector2 trans);

vector2 vector2_world_to_local(vector2 vector,vector2 hull_pos,rat_real hull_angle);
vector2 vector2_local_to_world(vector2 vector,vector2 hull_pos,rat_real hull_angle);

#ifdef __cplusplus
};
#endif

#endif
